﻿
namespace ria_project.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // Implements application logic using the InvEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class DomainService1 : LinqToEntitiesDomainService<InvEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Employees' query.
        public IQueryable<Employee> GetEmployees()
        {
            return this.ObjectContext.Employees;
        }

        public void InsertEmployee(Employee employee)
        {
            if ((employee.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(employee, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Employees.AddObject(employee);
            }
        }

        public void UpdateEmployee(Employee currentEmployee)
        {
            this.ObjectContext.Employees.AttachAsModified(currentEmployee, this.ChangeSet.GetOriginal(currentEmployee));
        }

        public void DeleteEmployee(Employee employee)
        {
            if ((employee.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(employee, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Employees.Attach(employee);
                this.ObjectContext.Employees.DeleteObject(employee);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Items' query.
        public IQueryable<Item> GetItems()
        {
            return this.ObjectContext.Items;
        }

        public void InsertItem(Item item)
        {
            if ((item.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(item, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Items.AddObject(item);
            }
        }

        public void UpdateItem(Item currentItem)
        {
            this.ObjectContext.Items.AttachAsModified(currentItem, this.ChangeSet.GetOriginal(currentItem));
        }

        public void DeleteItem(Item item)
        {
            if ((item.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(item, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Items.Attach(item);
                this.ObjectContext.Items.DeleteObject(item);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Orders' query.
        public IQueryable<Order> GetOrders()
        {
            return this.ObjectContext.Orders;
        }

        public void InsertOrder(Order order)
        {
            if ((order.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(order, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Orders.AddObject(order);
            }
        }

        public void UpdateOrder(Order currentOrder)
        {
            this.ObjectContext.Orders.AttachAsModified(currentOrder, this.ChangeSet.GetOriginal(currentOrder));
        }

        public void DeleteOrder(Order order)
        {
            if ((order.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(order, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Orders.Attach(order);
                this.ObjectContext.Orders.DeleteObject(order);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Stuffs' query.
        public IQueryable<Stuff> GetStuffs()
        {
            return this.ObjectContext.Stuffs;
        }

        public void InsertStuff(Stuff stuff)
        {
            if ((stuff.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(stuff, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Stuffs.AddObject(stuff);
            }
        }

        public void UpdateStuff(Stuff currentStuff)
        {
            this.ObjectContext.Stuffs.AttachAsModified(currentStuff, this.ChangeSet.GetOriginal(currentStuff));
        }

        public void DeleteStuff(Stuff stuff)
        {
            if ((stuff.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(stuff, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Stuffs.Attach(stuff);
                this.ObjectContext.Stuffs.DeleteObject(stuff);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Suppliers' query.
        public IQueryable<Supplier> GetSuppliers()
        {
            return this.ObjectContext.Suppliers;
        }

        public void InsertSupplier(Supplier supplier)
        {
            if ((supplier.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(supplier, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Suppliers.AddObject(supplier);
            }
        }

        public void UpdateSupplier(Supplier currentSupplier)
        {
            this.ObjectContext.Suppliers.AttachAsModified(currentSupplier, this.ChangeSet.GetOriginal(currentSupplier));
        }

        public void DeleteSupplier(Supplier supplier)
        {
            if ((supplier.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(supplier, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Suppliers.Attach(supplier);
                this.ObjectContext.Suppliers.DeleteObject(supplier);
            }
        }
    }
}


